package org.ksug.samples.springmvc;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

public class AccountValidator implements Validator {

	private static final String NAME = "name";
	private static final String NUMBER = "number";

	@SuppressWarnings("unchecked")
	@Override
	public boolean supports(Class clazz) {
		return Account.class.equals(clazz);
	}

	@Override
	public void validate(Object object, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, NUMBER, null,
				"번호는 반드시 입력해야 합니다.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, NAME, null, "이름은 반드시 입력해야 합니다.");
	}

}
